package com.cheng.commonutlis.avtivity;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Rect;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.cheng.commonlibrary.activity.CommonActivity;
import com.cheng.commonutlis.R;
import com.cheng.guidelibrary.MeasureUtil;
import com.cheng.guidelibrary.UserGuideView;

import java.util.LinkedHashMap;

public class Main5Activity extends CommonActivity {


    private String[] datas = new String[]{"收藏", "字体大小", "软件设置", "换肤"};
    private GridView mGridView;
    private UserGuideView guideView;
    private ImageView bottom, topLeft, top,topRight ,bottomLeft, bottomRight;

    private View tipTextView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main5);


        ActionBar supportActionBar = getSupportActionBar();
        if (null != supportActionBar) {
            supportActionBar.hide();
        }


        guideView = findViewById(R.id.guideView);
        guideView.setTouchOutsideDismiss(false);
        guideView.setStatusBarHeight(MeasureUtil.getStatuBarHeight(this));

        tipTextView = LayoutInflater.from(this).inflate(R.layout.custom_tipview, null);
        mGridView =  findViewById(R.id.gridview);
        mGridView.setAdapter(new MyAaapter());


        top = (ImageView) findViewById(R.id.top);
        topLeft = (ImageView) findViewById(R.id.top_left);
        topRight = (ImageView) findViewById(R.id.top_right);
        bottom = (ImageView) findViewById(R.id.bottom);
        bottomLeft = (ImageView) findViewById(R.id.bottomleft);
        bottomRight = (ImageView) findViewById(R.id.bottomRight);

        bottom.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                guideView.setTipView(tipTextView, 400, 200);
//                guideView.setTipViewMoveX(bottom,-200);
                guideView.setHighLightView(bottom);
                Rect rect = new Rect();
                bottom.getGlobalVisibleRect(rect);
                Log.d("guideViewTop", "bottom: " + rect.top);
            }
        });
        topLeft.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                guideView.setTipView(tipTextView, 400, 200);
                guideView.setHighLightView(topLeft);
            }
        });
        top.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                guideView.setArrowUpCenter(R.mipmap.up_arrow);
                guideView.setTipView(R.mipmap.tip_view);
                guideView.setHighLightView(top);
            }
        });

        LinkedHashMap<View, Integer> targets = new LinkedHashMap<>();
//        targets.put(top, R.mipmap.panda);
//        targets.put(topLeft, R.mipmap.tip3);
//        targets.put(topRight, R.mipmap.tip3);
        targets.put(bottom, R.mipmap.tip2);
        targets.put(bottomLeft, R.mipmap.tip3);
        targets.put(bottomRight, R.mipmap.tip_view);
//        guideView.setHighLightView(top,icon,back);
        guideView.setArrowDownRight(R.mipmap.guide_arrow_right);
        guideView.setArrowDownCenter(R.mipmap.guide_arrow_left);
        guideView.setArrowDownLeft(R.mipmap.guide_arrow_left);
        guideView.setArrowUpLeftMoveX(-30);
        guideView.setArrowDownRightMoveX(0);
        guideView.setTipViewMoveX(bottomLeft,-60);
//        guideView.setTipViewMoveX(bottomRight,140);
        guideView.setTipViewMoveX(topRight,-50);
        guideView.setArrowDownLeftMoveX(-20);
//        guideView.setArrowDownCenterMoveX(100);
//        guideView.setTipViewMoveX(icon,-100);
//        guideView.setTipViewMoveY(icon,100);
        guideView.setHighLightView(targets);
    }

    @Override
    protected int loadLayoutResId() {
        return 0;
    }


    private class MyAaapter extends BaseAdapter {

        @Override
        public int getCount() {
            return datas.length;
        }

        @Override
        public Object getItem(int position) {
            return datas[position];
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder viewHolder = null;
            if (convertView == null) {
                viewHolder = new ViewHolder();
                convertView = LayoutInflater.from(getActivity()).inflate(R.layout.grid_item, parent, false);
                viewHolder.textView = (TextView) convertView.findViewById(R.id.tx);
                convertView.setTag(viewHolder);
            } else {
                viewHolder = (ViewHolder) convertView.getTag();
            }
            viewHolder.textView.setText(datas[position]);
            return convertView;
        }

        private class ViewHolder {
            public TextView textView;
        }
    }
}
